package com.frinder.robot.handler;

import akka.actor.ActorRef;
import akka.actor.ActorSelection;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @ClassName RobotActor
 * @Description 机器人处理器
 * @Author frinder
 * @Date 2019/10/22 10:26
 * @Verion 1.0
 */
@Component
@Scope("prototype")
public class RobotActor extends BaseRobotActor {

    public static final String NAME = "robot-actor-%s";

    private final ActorSelection robotTaskManagerActor;

    public RobotActor(String robotName, ActorSelection robotTaskManagerActor) {
        super(robotName);
        this.robotTaskManagerActor = robotTaskManagerActor;
    }

    @Override
    public void preStart() throws Exception {
        super.preStart();
        ActorRef robotTaskActor = actors.getActorRef("robotTaskActor",
                String.format(RobotTaskActor.NAME, this.robotName),
                this.robotName,
                this.robotTaskManagerActor
        );
        ActorRef robotActionActor = actors.getActorRef("robotActionActor",
                String.format(RobotActionActor.NAME, this.robotName),
                this.robotName
        );
        getContext().watch(robotTaskActor);
        getContext().watch(robotActionActor);
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder()
                .build();
    }
}
